Skip to content

Share test stubs, and show a per-node style in the styles example - #543

Merged
paceholder merged 2 commits into
masterfrom
example/per-node-style
Nov 23, 2026
Merged

paceholder merged 2 commits into
masterfrom
example/per-node-style

Conversation

@paceholder

@paceholder paceholder commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation/refactoring

Description

Two commits. The first is a test-only refactor. The second shows a per-node style in an example.

  1. Share the stub delegate model and the lockable model between tests (Tests: share the stub delegate model and the lockable model #553). The tests repeated the same seven overrides of NodeDelegateModel in many small classes, and had two lockable models. They now use two header-only files: test/include/TestDelegateModels.hpp (StubDelegateModel, with name, caption and port counts as constructor parameters) and test/include/LockableModel.hpp (LockableModel<Base>, which replaces LockableGraphModel and the old LockableModel). Six test files use the stub. Registry setup stays in each test. Behavior is unchanged. The net size of the tests is about the same (-6 lines): the new headers are as long as what was removed, and each plain stub still needs a small creator function for registration. The gain is that a new test can derive from the stub instead of copying the block.
  2. Show a per-node style in the styles example (Add simple example for custom per-Node style #87). examples/styles now has a second node type, MyGreenDataModel. Its delegate model calls setNodeStyle() in the constructor, so it keeps its own green style next to the global one. The example starts with two nodes of each type. The "Per-Node Styling" section of the styling guide points to it. The example is the right place for it: simple_graph_model is meant to show the model itself, so I did not change it.

Testing

  • Qt version tested: Qt 6.12.0, macOS (Apple Clang)
  • Existing tests still pass: 761 assertions in 69 test cases, the same numbers as before the refactor, with the same section counts for every test case. All examples build.
  • The look of the styles example was checked with an offscreen screenshot: mint nodes with a gray border (global style) next to green nodes with a green border (per-node style).
  • Not tested: Qt 5, MSVC, Apple Clang with -Werror (CI covers them).

Breaking changes?

No. Tests, one example and one docs section only.

Related issue

Fixes #553
Related to #87.

Add test/include/TestDelegateModels.hpp with StubDelegateModel. It takes
a name, a caption and the port counts. Six tests now use it or derive
from it instead of repeating the seven overrides: TestDataFlowGraphModel,
TestSerialization, TestNodeGroup, TestNodeNickname, TestNodeStyleRole and
TestNodeValidation. StyledModel and TestValidatedModel lose Q_OBJECT and
their .moc includes. They have no signals or slots of their own.

Add test/include/LockableModel.hpp with the template LockableModel<Base>.
It replaces the two lockable models in TestLockedNodePress and
TestNodeGroup. The lock is now kept per node in both.

Registry setup stays in each test. TestModelWithName,
TestModelWithStaticName and EagerWidgetModel stay local.

Behavior is unchanged: 69 test cases and 761 assertions, with the same
per-section counts as before. Net change: -6 lines.

Fixes #553
Issue #87 asks for an example of a custom per-node style.

The styles example now has a second node type, MyGreenDataModel. Its
delegate model sets its own background and border color with
setNodeStyle(). It looks different from MyDataModel, which uses the
global style.

The example starts with two nodes of each type side by side.

The styling guide points to this example.
@paceholder
paceholder force-pushed the example/per-node-style branch from 2c8e577 to e8bbc08 Compare November 23, 2026 00:50
@paceholder paceholder changed the title Show a per-node style in simple_graph_model Share test stubs, and show a per-node style in the styles example Nov 23, 2026
@paceholder
paceholder merged commit eadba64 into master Nov 23, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tests: share the stub delegate model and the lockable model

1 participant